<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>添加调查问卷</title>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
  <script src="/scripts/jquery.min.js"></script>
  <script src="/scripts/boot.js" type="text/javascript"></script>
  <script src="/scripts/miniui/miniui.js"></script>

  <style type="text/css">
    html, body {
      font-size: 12px;
      padding: 0;
      margin: 0;
      border: 0;
      height: 100%;
      overflow: hidden;
    }
  </style>
</head>
<body>

<form id="form1" name="form1" method="post" action='' enctype="multipart/form-data" >
  <input name="id" class="mini-hidden" />
  <div style="padding-left:11px;padding-bottom:5px; margin-top: 20px">
    <table style="table-layout:fixed; margin: 0 auto;text-align: center;">
      <tr>
        <td style="width:60px;">问卷标题：</td>
        <td >
          <input id="title" name="title" class="mini-textbox" style="width:155px;" type="text" required="true" />
        </td>
      </tr>
      <tr>
        <td style="width:60px;">问卷网址：</td>
        <td >
          <input id="url" name="url" class="mini-textbox" style="width:155px;" type="text" required="true" />
        </td>
      </tr>
      <tr>
        <td style="width:60px;">问卷类型：</td>
        <td >
          <input id="type" name="type" class="mini-combobox" style="width:155px; " data="questionType" value="1" type="text"/>
        </td>
      </tr>

    </table>
  </div>
  <div style="text-align:center;padding:10px;">
    <a class="mini-button" onclick="onOk" style="width:60px;margin-right:20px;">确定</a>
    <a class="mini-button" onclick="onCancel" style="width:60px;">取消</a>
  </div>
</form>
<script type="text/javascript">
  var questionType = [{ id: 0, text: 'LIVE' }, { id: 1, text: 'TASK'}];
  mini.parse();
  var form = new mini.Form("form1");

  function SaveData() {
    var form = new mini.Form("#form1");
//    var data = form.getData();      //获取表单多个控件的数据
    form.validate();
    let data = {}
    data.title = mini.get('title').value;
    data.url = mini.get('url').value;
    let type = mini.get('type').value;
    if (type == 0){
      data.type = 'LIVE'
    } else {
      data.type = 'TASK'
    }
//    console.log(data)
    $.ajax({
      url: "/getdata/questionAdd",
      type: 'post',
      data: data,
      cache: false,
      success: function (result) {
        if (result){
          alert('问卷调查添加成功！');
          CloseWindow("close");
        } else {
          alert('问卷调查添加失败！');
        }
      },
      error: function (error) {
        console.log(error)
      }
    });
  }

  //标准方法接口定义
  function SetData(data) {
  }

  function GetData() {
    var o = form.getData();
    return o;
  }

  function CloseWindow(action) {
    if (action == "close" && form.isChanged()) {
      if (confirm("数据被修改了，是否先保存？")) {
        return false;
      }
    }
    if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
    else window.close();
  }

  function onOk(e) {
    SaveData();
  }

  function onCancel(e) {
    CloseWindow("cancel");
  }

</script>
</body>
</html>
